package com.yyplatform.admin.platform.init.data;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;

import com.yyplatform.admin.platform.role.model.entity.SysMenuEntity;
import com.yyplatform.admin.platform.role.model.enums.MenuTypeEnum;
import com.yyplatform.admin.platform.role.repository.SysMenuRepository;
import com.yyplatform.admin.platform.role.service.SysMenuService;

/**
 * @author sleepforests@163.com
 * <p>
 * Created on 2024/11/16 20:42
 */

public class InitMenuData7Wechat {

    private SysMenuRepository sysMenuRepository;

    private SysMenuService sysMenuService;

    public InitMenuData7Wechat(SysMenuRepository sysMenuRepository1, SysMenuService sysMenuService1) {
        sysMenuRepository = sysMenuRepository1;
        sysMenuService = sysMenuService1;
    }

    public void init() {
        List<SysMenuEntity> list = sysMenuRepository.findAll();

        String name = "微信管理";

        Optional<SysMenuEntity> rootOptional =
                list.stream().filter(e -> StringUtils.equals(e.getName(), name)).findFirst();
        if (rootOptional.isPresent()) {
            return;
        }

        SysMenuEntity menu = new SysMenuEntity();
        menu.setAlwaysShow(true);
        menu.setComponent("Layout");
        menu.setEnabled(true);
        menu.setIcon("wechat");
        menu.setKeepAlive(true);
        menu.setName(name);
        menu.setOrderNum(100);
        menu.setParams(Collections.emptyList());
        menu.setPermissions("");
        menu.setPid(0L);
        menu.setRedirect("");
        menu.setRemark("");
        menu.setRouteName("");
        menu.setRoutePath("/wechat");
        menu.setVisible(true);

        menu.setMenuType(MenuTypeEnum.MENU_TYPE_FOLDER.getValue());

        sysMenuRepository.save(menu);


    }

}



